<extend name="Public:base" />
<block name="content">
<section id="goods-show" >
	<div id="content" class="main container">
		<div class="col-main">
			<div class="row">
			<div class="container">
				<div class="alert alert-success hidden" role="alert">
				  <button type="button" class="close"><span aria-hidden="true">&times;</span></button>
				  <div id="success"></div>
				</div>
					
				<div class="alert alert-danger hidden" role="alert">
				  <button type="button" class="close"><span aria-hidden="true">&times;</span></button>
				  <div id="fail"></div>
				</div>
			</div>	
				<div class="product-view col-md-9">
					<div class="product-essential">
						
						<div class="product-img-box col-xs-12 col-sm-6 col-md-6 col-lg-5">
							<div class="product-image">
								<div class="large-image"> 
				                  <a href="__ROOT__/Uploads/image/{$goods.image}" class="cloud-zoom" id="zoom1" rel="" > 
				                    <img src="__ROOT__/{$goods.image_thumb}"> 
				                  </a> 
				                </div>
				                
				                <div class="flexslider flexslider-thumb">
				                    <ul class="previews-list slides">
				                       <?php foreach ($goods_image as $image) { ?>
				                       <li>
				                        <a href="__ROOT__/Uploads/image/<?php echo $image['image']; ?>" title="" class="cloud-zoom-gallery" rel="useZoom: 'zoom1', smallImage: '__ROOT__/<?php echo $image['image_360_360']; ?>'">
				                          <img src="__ROOT__/<?php echo $image['thumb']; ?>" alt = "Thumbnail 1"/>
				                        </a>
				                      </li>
				                       <?php }?>
				                    </ul>
				                </div>
				                
							</div>
						</div>
						<div class="product-shop col-xs-12 col-sm-6 col-md-6 col-lg-7">
							<div class="product-name">
								<h1>{$goods.name}</h1>
							</div>
							
							 
							
							<div class="price-block">
								<div class="price-box">
									<p class="regular-price">
										<span class="price">￥<?php echo round($goods['price'] ,2); ?></span>
									</p>
								</div>
							</div>
							
							<ul class="list-unstyled">								
								<li>型号 ：{$goods.model}</li>
								<li>生产地 ：{$goods.location}</li>
								<li>重量：<?php echo round($goods['weight'] ,2).get_weight_name($goods['weight_class_id']); ?></li>
								<li>规格： 长 <?php echo round($goods['length'] ,2).get_length_name($goods['length_class_id']); ?>  
									宽 <?php echo round($goods['width'] ,2).get_length_name($goods['length_class_id']); ?>  
									高 <?php echo round($goods['height'] ,2).get_length_name($goods['length_class_id']); ?> 
								</li>
									
							<?php if(isset($discount)){ ?>
									<?php foreach ($discount as $k => $v){ ?>
										<li><?php echo $v['quantity'].'个 或更多 ￥'.$v['price']; ?></li>
									<?php } ?>									
								<?php } ?>
							</ul>
							
						  
					      <?php if ($options) { ?>
						      <div class="options">
						        <h2>可选项</h2>
						        <?php foreach ($options as $option) { ?>  	
						        <?php if ($option['type'] == 'select') { ?>
						        	<div class="boss_check">
						        <div class="box-check">	
						        <div id="option-<?php echo $option['goods_option_id']; ?>" class="option">
						          <div class="title_text"><b><?php echo $option['name']; ?>:</b>
						          <?php if ($option['required']) { ?>
						          <span class="required">*</span>
						          <?php } ?></div>
						          <select name="option[<?php echo $option['goods_option_id']; ?>]">
						            <option value=""> --- 请选择 --- </option>
						            <?php foreach ($option['option_value'] as $option_value) { ?>
						            <option value="<?php echo $option_value['goods_option_value_id']; ?>"><?php echo $option_value['name']; ?>
						            <?php if ($option_value['price']) { ?>
						            (<?php echo $option_value['price_prefix']; ?><?php echo $option_value['price']; ?>)
						            <?php } ?>
						            </option>
						            <?php } ?>
						          </select>
						        </div>
						         </div>
						         </div>
						        <?php } ?>
						      
						        
						        
						        <?php if ($option['type'] == 'radio') { ?>
								<div class="boss_check">
									<div class="box-check">
								        <div id="option-<?php echo $option['goods_option_id']; ?>">
								          <p><b><?php echo $option['name']; ?>:</b>
								          <?php if ($option['required']) { ?>
								          <span class="required">*</span>
								          <?php } ?></p>
								          <?php foreach ($option['option_value'] as $option_value) { ?>								        						         
								          									          	
								          <label for="option-value-<?php echo $option_value['goods_option_value_id']; ?>">								          	
								          	<input  class="option" type="radio" name="option[<?php echo $option['goods_option_id']; ?>]" value="<?php echo $option_value['goods_option_value_id']; ?>" id="option-value-<?php echo $option_value['goods_option_value_id']; ?>" />								          	       										          	
									          	<?php if(!empty($option_value['image'])) { ?>		
										          	<a href="__ROOT__/Uploads/image/<?php echo $option_value['image']; ?>" class="cloud-zoom-gallery" rel="useZoom: 'zoom1', smallImage: '<?php echo '/'.resize($option_value['image'],360,360); ?>'">
										          		<img src="__ROOT__/<?php echo resize($option_value['image'],30,30); ?>" />									          										          
										          	</a>
									          	 <?php } ?>	
									          	<?php echo $option_value['name']; ?>
									            <?php if ($option_value['price']) { ?>
									            (<?php echo $option_value['price_prefix']; ?><?php echo $option_value['price']; ?>)
									            <?php } ?>								            
								          </label>										     
								           
								          <br />
								          <?php } ?>
								        </div>
									</div>
								</div>	
						        <?php } ?>
						        
						        <?php if ($option['type'] == 'checkbox') { ?>
								<div class="box-check">
						        <div id="option-<?php echo $option['goods_option_id']; ?>" class="option">
						          <p><b><?php echo $option['name']; ?>:</b>
						          <?php if ($option['required']) { ?>
						          <span class="required">*</span>
						          <?php } ?></p>
						          <?php foreach ($option['option_value'] as $option_value) { ?>
						          <input type="checkbox" name="option[<?php echo $option['goods_option_id']; ?>][]" value="<?php echo $option_value['goods_option_value_id']; ?>" id="option-value-<?php echo $option_value['goods_option_value_id']; ?>" />
						          <label for="option-value-<?php echo $option_value['goods_option_value_id']; ?>">
						           <?php if(!empty($option_value['image'])) { ?>		
						          	<a href="__ROOT__/Uploads/image/<?php echo $option_value['image']; ?>" class="cloud-zoom-gallery" rel="useZoom: 'zoom1', smallImage: '<?php echo '/'.resize($option_value['image'],360,360); ?>'">
						          		<img src="__ROOT__/<?php echo resize($option_value['image'],30,30); ?>" />									          										          
						          	</a>
					          	 <?php } ?>	
						           <?php echo $option_value['name']; ?>
						            <?php if ($option_value['price']) { ?>
						            (<?php echo $option_value['price_prefix']; ?><?php echo $option_value['price']; ?>)
						            <?php } ?>
						          </label>
						          <br />
						          <?php } ?>
						        </div>
						        </div>
													       
						        <?php } ?>						      
						        <?php } ?>
						      </div>
						      <?php } ?>				  
							 
							
							<div id="product">
								<hr>
							
							<div class="add-to-box">
                       
				            <div class="add-to-cart">

				              <div class="pull-left">
				              <div class="select_number">	
								<input class="text" type="text" id="quantity" value="1" size="2" name="quantity">
								<button class="increase" onclick="changeQty(1); return false;">+</button>
								<button class="decrease" onclick="changeQty(0); return false;">-</button>
								</div>
								<input type="hidden" value="{$goods.goods_id}" size="2" name="goods_id">
				                </div> 
				
				                <div class="pull-left">
					                <button id="button-cart" class="button btn-cart" data-loading-text="Loading..." type="button">
										<span>加入购物车</span>
									</button>
				              
				            	</div>
				            
					 
				
				          </div>
							
							
							</div>
							
						</div>
						
					</div>
				</div>
				
				
				<div class="product-collateral col-lg-12 col-sm-12 col-xs-12">
					<div class="add_info">
						<ul id="product-detail-tab" class="nav nav-tabs product-tabs">	
							<li class="active">
								<a data-toggle="tab" href="#product_tabs_description">商品描述</a>
							</li>
							
						</ul>
						<div id="productTabContent" class="tab-content">
							<div id="product_tabs_description" class="tab-pane active">
								<div class="std"><?php echo htmlspecialchars_decode($goods['description']); ?></div>
							</div>
							
							
						</div>
					</div>		
				</div>
				
				<div class="hidden-xs hidden-sm" id="related">
					<div class="product-collateral col-lg-12 col-sm-12 col-xs-12">
						{~W('Product/related_goods_list')}
					</div>
				</div>
				
			</div>
			<div class="col-md-3 hidden-xs hidden-sm">
				{~W('Product/hot_goods_list',array('热门产品','viewed desc','5'))}
			</div>
		</div>
	</div>
	</div>
</section>
</block>

<block name="foot_script">

<link type="text/css" rel="stylesheet" href="__PUBLIC__/font-awesome/css/font-awesome.min.css">		
<link href="__JS__/flexslider/flexslider.css" rel="stylesheet" type="text/css"> 	
<link href="__JS__/cloud-zoom/cloud-zoom.1.0.3.css" rel="stylesheet" type="text/css" />

<script src="__JS__/cloud-zoom/cloud-zoom1.js"></script>
<script src="__JS__/flexslider/jquery.flexslider.js"></script>

<script>
function changeQty(increase) {
    var qty = parseInt($('.select_number').find("input").val());
    if ( !isNaN(qty) ) {
        qty = increase ? qty+1 : (qty > <?php echo $goods['minimum']; ?> ? qty-1 : <?php echo $goods['minimum']; ?>);
        $('.select_number').find("input").val(qty);
    }
}	
$('#button-cart').bind('click', function() {

	$.ajax({
		url: "{:U('/cart_add')}",
		type: 'post',
		data: $('#content input[type=\'text\'],#content input[type=\'hidden\'],#content input[type=\'radio\']:checked,#content input[type=\'checkbox\']:checked,#content select'),
		dataType: 'json',
		success: function(json) {
			
			$('.alert').addClass('hidden');
			
			$('.box-check').removeClass('text-error');
			
			$('.text-danger').remove();
			if (json['error']) {
			
                 if (json['error']['option']) {
		          for (i in json['error']['option']) {
		            var element = $('#option-'+i);
		
		            if (element.parent().hasClass('box-check')) {
		              element.parent().addClass('text-error').after('<div class="text-danger">' + json['error']['option'][i] + '</div>');
		            } else {
		              element.after('<div class="text-danger">' + json['error']['option'][i] + '</div>');
		            }
		          }
					}
					
					// $('.text-danger').parent().addClass('has-error');
		}	
			
			if (json['success']) {				
				$('.alert-success').removeClass('hidden');
				$('#success').text(json['success']);
				$('#cart-total').text(json['total']);
			}else if(json['error']['quantity']){
				$('.alert-danger').removeClass('hidden');
				$('#fail').text(json['error']['quantity']);
			}	
			
		}
	});	
});

$('.close').click(function(){
	$(this).parent().addClass('hidden');
});
	

</script>

</block>